 $(function() {
    //  //如果没有登录 跳回首页
    //  if (localStorage.getItem('token') == null) {
    //      alert('请先登录');
    //      window.location.href = './login.html';
    //  }
     //点左上返回按钮 返回首页
     $(".return-btn").click(function() {
         console.log("return-btn===============")
             async function logout() {
                 try {
                     let res = await jqAjax('GET', '/logout', '')
                     console.log(res);
                     localStorage.removeItem('role');
                     localStorage.removeItem('username');
                     location.href = '/tologin';
                 } catch (error) {
                     console.log('catch');
                     console.log(error);
                 }
             }
             debounce(logout(), 300);
         })
         //侧边栏下拉
     var downFalg = 1;
     //设备管理
     $("#back-stage").on("click", function() {
             if (downFalg == 1) {
                 $(".back-stage-management").css("height", "250");
                 $(".back-stage-item").stop().slideDown();
                 downFalg = 0;
             } else {
                 $(".back-stage-management").css("height", "50");
                 $(".back-stage-item").stop().slideUp();
                 downFalg = 1;
             }
         })
    // //设备查询
    // $("#eq-q").on("click", function() {
    //     document.getElementsByClassName("content").src = "/home"
    // })




       $(".eqdiv").click(function() {
           window.location.href = '/index?'+'url=toequipment'+'&page=1&per_page=10'
         })
       $(".sediv").click(function() {
           window.location.href = '/index?'+'url=toservice'+'&page=1&per_page=10'
         })
       $(".udiv").click(function() {
           window.location.href = '/index?'+'url=touser'+'&page=1&per_page=10'
         })
       $(".rediv").click(function() {
           window.location.href = '/index?'+'url=torecord'+'&page=1&per_page=10'
         })
       $(".efdiv").click(function() {
           window.location.href = '/index?'+'url=toequipmentfault'+'&page=1&per_page=10'
         })





        $(".deleteequipment").click(function() {
            console.log("=============deleteequipment=======")
          let eqid = $('.eqid').val();
              console.log(eqid)

          let arr=[eqid]
           async  function delequipment() {
                 console.log("进入了delequipment")
                     try {
                         let res =  await jqAjax('POST', '/equipment/del', JSON.stringify({
                                 eq_id_list: arr, //加密
                             }))
                         console.log(res)
                         if (res.msg=="删除成功"){
                               window.location.href = '/index?index=1&page=1&per_page=10'
                         }else {
                             alert("注册失败")
                         }

                         //baseAPI里的函数传参
                         // console.log('点击登录try');
                         // console.log('token:' + res.token);
                         // localStorage.setItem('token', res.token);
                         // $(".uname").val(''); //登录进去之后把用户名密码删掉
                        //跳转到主页面

                     } catch (error) {
                         console.log('catch');
                         alert('用户名或密码错误 , 请重新输入');
                     }
                 }
            delequipment()
        })



         //题库管理
     $("#test-base").on("click", function() {
             if (downFalg == 1) {
                 $(".test-base-management").css("height", "250");
                 $(".test-base-item").stop().slideDown();
                 downFalg = 0;
             } else {
                 $(".test-base-management").css("height", "50");
                 $(".test-base-item").stop().slideUp();
                 downFalg = 1;
             }
         })
         //学科管理
     $("#discipline").on("click", function() {
         if (downFalg == 1) {
             $(".discipline-management").css("height", "200");
             $(".discipline-item").stop().slideDown();
             downFalg = 0;
         } else {
             $(".discipline-management").css("height", "50");
             $(".discipline-item").stop().slideUp();
             downFalg = 1;
         }
     })

     //路由跳转

    //  function Router(parames) {
    //      //将函数内this环境绑定到函数内，而不是window
    //      if (!(this instanceof Router)) {
    //          return new Router(arguments)
    //      }
    //      let router = {};
    //      router.routes = parames.routes || [];
    //      router.target = parames.target || "";
    //      router.index = parames.index || "";
    //      console.log(this); //Router
    //      this.loadIndex(router);
    //      //点击需要跳转的链接
    //      document.querySelectorAll(".router").forEach((item, index) => {
    //          item.addEventListener("click", function(e) {
    //              e.preventDefault();
    //              window.location.href = `#${this.getAttribute("href")}`;
    //          }, false);
    //      });
    //      //当hash发生改变
    //      window.addEventListener("hashchange", function() {
    //          this.routerLoad(router);

    //      }.bind(this));
    //  };
    //  //定义Router原型
    //  Router.prototype = {
    //      routerLoad: router => {
    //          console.log(444);
    //          let nowHash = window.location.hash;
    //          console.log(nowHash);
    //          let index = router.routes.findIndex((item, index) => {
    //              return nowHash == ('#' + item.path);
    //          });
    //          document.querySelector(`${router.target}`).src = router.routes[index].component;
    //      },
    //      loadIndex: router => {
    //          console.log(window.location.hash);
    //          window.location.hash = '#/home';
    //          document.querySelector(`${router.target}`).src = router.index;
    //      }
    //  }
    //  window.Router = Router;
    //  //构造函数
    //  new Router({
    //      target: '#mainiframe',
    //      index: 'home.html', //默认页
    //      routes: [{
    //          path: '/home',
    //          component: 'home.html'
    //      }, {
    //          path: '/add',
    //          component: 'add.html'
    //      }]
    //  });
 })